sf_trees <- read.csv(here("data", "sf_trees", "sf_trees.csv"))
top_5_status <- sf_trees %>%
group_by(legal_status) %>%
summarize(tree_count = n()) %>%
slice_max(tree_count, n = 5) %>%
arrange(-tree_count)
tree_plot <- ggplot(data = top_5_status, aes(x = fct_reorder(legal_status, tree_count),
y = tree_count)) +
geom_col() +
labs(y = 'Tree count', x = 'Legal Status') +
coord_flip() +
theme_minimal()
tree_plot
permitted_mia <- sf_trees %>%
filter(legal_status == "Permitted Site" & caretaker == "MTA")
blackwood_acacia <- sf_trees %>%
filter(str_detect(species, "Blackwood Acacia")) %>%
select(legal_status, date, latitude, longitude)
#str_detect for if the name like this is next to another scientific name
### now make a plot
ggplot(data = blackwood_acacia, aes(x = longitude, y = latitude)) + geom_point()
sf_tress_sep <- sf_trees %>% separate(species, into = c('spp_scientific', 'spp_common'), sep = " :: ")
sf_trees_unite <- sf_trees %>%
unite("id_status", tree_id:species, sep = '_NEW_')
blackwood_acacia_sf <- blackwood_acacia %>%
drop_na(longitude, latitude) %>%
st_as_sf(coords = c('longitude', 'latitude'))
# now you have coordinates as points and can plot them using simple features tool
st_crs(blackwood_acacia_sf) <- 4326 #basically a coordinate reference system, basic latitude and longitude
ggplot(data = blackwood_acacia_sf) + geom_sf(color = 'darkgreen') + theme_minimal()
### Read in SF streets data (sf in this case at the end stands for
simple features)
sf_map_sf <- read_sf(here('data', 'sf_map', 'tl_2017_06075_roads.shp')) %>%
st_transform(4326)
# st_crs(sf_map_sf) see what coordinate system you are working with and itf you have to change it
ggplot() +
geom_sf(data = sf_map_sf, size = 0.1, color = 'darkgrey') +
geom_sf(data = blackwood_acacia_sf, color = 'darkgreen', size = 0.5) + theme_void() +
labs(title = 'Blackwood acacias in San Francisco')
tmap_mode('view')
## tmap mode set to interactive viewing
tm_shape(blackwood_acacia_sf) + tm_dots()